setwd("~/Desktop/Replication Archive")

#####STUDY 2 MICHIGAN#####
study2_mi <- read.csv("study2_mi.csv", stringsAsFactors=FALSE)

####TREATMENTS####
###FAVOR CHANGE IS ALWAYS = 2 AND OPPOSE CHANGE IS ALWAYS = 1
#EMERGENCY MGR
study2_mi$PROP1_SQ <- NA
study2_mi$PROP1_SQ[study2_mi$Q60 == 2] <- 1
study2_mi$PROP1_SQ[study2_mi$Q60 == 1] <- 0
study2_mi$PROP1_SQ[study2_mi$Q62 == 2] <- 1
study2_mi$PROP1_SQ[study2_mi$Q62 == 1] <- 0
study2_mi$PROP1_TREAT <- as.numeric(!is.na(study2_mi$Q62))

#COLLECTIVE BARGAINING
study2_mi$PROP2_SQ <- NA
study2_mi$PROP2_SQ[study2_mi$Q128.1 == 2] <- 1
study2_mi$PROP2_SQ[study2_mi$Q128.1 == 1] <- 0
study2_mi$PROP2_SQ[study2_mi$Q98 == 2] <- 1
study2_mi$PROP2_SQ[study2_mi$Q98 == 1] <- 0
study2_mi$PROP2_TREAT <- as.numeric(!is.na(study2_mi$Q98))

#ENERGY
study2_mi$PROP3_SQ <- NA
study2_mi$PROP3_SQ[study2_mi$Q179 == 2] <- 1
study2_mi$PROP3_SQ[study2_mi$Q179 == 1] <- 0
study2_mi$PROP3_SQ[study2_mi$Q180 == 2] <- 1
study2_mi$PROP3_SQ[study2_mi$Q180 == 1] <- 0
study2_mi$PROP3_TREAT <- as.numeric(!is.na(study2_mi$Q180))

#IN-HOME CARE
study2_mi$PROP4_SQ <- NA
study2_mi$PROP4_SQ[study2_mi$Q181 == 2] <- 1
study2_mi$PROP4_SQ[study2_mi$Q181 == 1] <- 0
study2_mi$PROP4_SQ[study2_mi$Q182 == 2] <- 1
study2_mi$PROP4_SQ[study2_mi$Q182 == 1] <- 0
study2_mi$PROP4_TREAT <- as.numeric(!is.na(study2_mi$Q182))

#TAXES
study2_mi$PROP5_SQ <- NA
study2_mi$PROP5_SQ[study2_mi$Q129.1 == 2] <- 1
study2_mi$PROP5_SQ[study2_mi$Q129.1 == 1] <- 0
study2_mi$PROP5_SQ[study2_mi$Q130.1 == 2] <- 1
study2_mi$PROP5_SQ[study2_mi$Q130.1 == 1] <- 0
study2_mi$PROP5_TREAT <- as.numeric(!is.na(study2_mi$Q130.1))

#BRIDGE
study2_mi$PROP6_SQ <- NA
study2_mi$PROP6_SQ[study2_mi$Q177 == 2] <- 1
study2_mi$PROP6_SQ[study2_mi$Q177 == 1] <- 0
study2_mi$PROP6_SQ[study2_mi$Q178 == 2] <- 1
study2_mi$PROP6_SQ[study2_mi$Q178 == 1] <- 0
study2_mi$PROP6_TREAT <- as.numeric(!is.na(study2_mi$Q178))
##################

####CREATE / RENAME VARIABLES####
study2_mi$MALE <- as.numeric(study2_mi$Q142 == 1)
study2_mi$AGE <- study2_mi$Q35_1
study2_mi$AGE[study2_mi$AGE==720] <- 72
study2_mi$EDUCATION <- study2_mi$Q60.1
study2_mi$INCOME <- study2_mi$Q59
study2_mi$LIBCON <- study2_mi$Q33 #LIBERAL TO CONSERVATIVE
study2_mi$RISK <- abs(11-study2_mi$Q54) #RISK AVERSION RESCALED SO THAT HIGHER VALUES MEAN MORE RISK AVERSE
study2_mi$INFORMED1 <- abs(6-study2_mi$Q124.1) #INFORMED ABOUT PROP 1
study2_mi$INFORMED2 <- abs(6-study2_mi$Q126.1) #INFORMED ABOUT PROP 2
study2_mi$INFORMED3 <- abs(6-study2_mi$Q128) #INFORMED ABOUT PROP 3
study2_mi$INFORMED4 <- abs(6-study2_mi$Q130) #INFORMED ABOUT PROP 4
study2_mi$INFORMED5 <- abs(6-study2_mi$Q132) #INFORMED ABOUT PROP 5
study2_mi$INFORMED6 <- abs(6-study2_mi$Q134) #INFORMED ABOUT PROP 6
study2_mi$IMPORT1 <- abs(6-study2_mi$Q123.1) #FEEL PROP 1 IS IMPORTANT
study2_mi$IMPORT2 <- abs(6-study2_mi$Q125.1) #FEEL PROP 2 IS IMPORTANT
study2_mi$IMPORT3 <- abs(6-study2_mi$Q127) #FEEL PROP 3 IS IMPORTANT
study2_mi$IMPORT4 <- abs(6-study2_mi$Q129) #FEEL PROP 4 IS IMPORTANT
study2_mi$IMPORT5 <- abs(6-study2_mi$Q131) #FEEL PROP 5 IS IMPORTANT
study2_mi$IMPORT6 <- abs(6-study2_mi$Q133) #FEEL PROP 6 IS IMPORTANT
study2_mi$BLACK <- as.numeric(study2_mi$Q37 == 2)
study2_mi$HISP <-  as.numeric(study2_mi$Q37 == 3)
study2_mi$WHITE <-  as.numeric(study2_mi$Q37 == 5)
study2_mi$PARTISAN <- NA
study2_mi$PARTISAN[study2_mi$Q25 == 2 & study2_mi$Q29 == 1] <- 1 #STRONG DEM
study2_mi$PARTISAN[study2_mi$Q25 == 2 & study2_mi$Q29 == 2] <- 2 #DEM
study2_mi$PARTISAN[study2_mi$Q25 == 3 & study2_mi$Q31 == 2] <- 3 #LEANING DEM
study2_mi$PARTISAN[study2_mi$Q25 == 3 & study2_mi$Q31 == 3] <- 4 #INDEPENDENT
study2_mi$PARTISAN[study2_mi$Q25 == 3 & study2_mi$Q31 == 1] <- 5 #LEANING REP
study2_mi$PARTISAN[study2_mi$Q25 == 1 & study2_mi$Q27 == 2] <- 6 #REP
study2_mi$PARTISAN[study2_mi$Q25 == 1 & study2_mi$Q27 == 1] <- 7 #STRONG REP
########################

####STACK THE DATA####
prop2 <- study2_mi[,c(39,40,49:54,56,62,67:69)]
prop2$PROP <- 2
prop2$ID <- rep(1:dim(prop2)[1])
prop3 <- study2_mi[,c(41,42,49:54,57,63,67:69)]
prop3$PROP <- 3
prop3$ID <- rep(1:dim(prop3)[1])
prop4 <- study2_mi[,c(43,44,49:54,58,64,67:69)]
prop4$PROP <- 4
prop4$ID <- rep(1:dim(prop4)[1])
prop5 <- study2_mi[,c(45,46,49:54,59,65,67:69)]
prop5$PROP <- 5
prop5$ID <- rep(1:dim(prop5)[1])
prop6 <- study2_mi[,c(47,48,49:54,60,66,67:69)]
prop6$PROP <- 6
prop6$ID <- rep(1:dim(prop6)[1])

names(prop2)[c(1,2,9,10)] <- names(prop3)[c(1,2,9,10)] <- names(prop4)[c(1,2,9,10)] <- names(prop5)[c(1,2,9,10)] <- names(prop6)[c(1,2,9,10)] <- c("SQ","TREAT","INFORMED","IMPORT")
props <- rbind(prop2,prop3,prop4,prop5,prop6)
props <- props[order(props$ID),]

library(foreign)
write.dta(props,file="props.dta")
########################

#####STUDY 2 CALIFORNIA#####
study2_ca <- read.csv("study2_ca.csv", stringsAsFactors=FALSE)

####TREATMENTS####
###FAVOR CHANGE IS ALWAYS = 2 AND OPPOSE CHANGE IS ALWAYS = 1
#TAXES
study2_ca$PROP30_SQ <- NA
study2_ca$PROP30_SQ[study2_ca$Q128.1 == 2] <- 1
study2_ca$PROP30_SQ[study2_ca$Q128.1 == 1] <- 0
study2_ca$PROP30_SQ[study2_ca$Q98 == 2] <- 1
study2_ca$PROP30_SQ[study2_ca$Q98 == 1] <- 0
study2_ca$PROP30_TREAT <- as.numeric(!is.na(study2_ca$Q98))

#DEATH PENALTY
study2_ca$PROP34_SQ <- NA
study2_ca$PROP34_SQ[study2_ca$Q60 == 2] <- 1
study2_ca$PROP34_SQ[study2_ca$Q60 == 1] <- 0
study2_ca$PROP34_SQ[study2_ca$Q177 == 2] <- 1
study2_ca$PROP34_SQ[study2_ca$Q177 == 1] <- 0
study2_ca$PROP34_TREAT <- as.numeric(!is.na(study2_ca$Q177))
##################

####CREATE / RENAME VARIABLES####
study2_ca$MALE <- as.numeric(study2_ca$Q142 == 1)
study2_ca$AGE <- study2_ca$Q35_1
study2_ca$AGE[study2_ca$AGE == 290] <- 29
study2_ca$AGE[study2_ca$AGE == 640] <- 64
study2_ca$EDUCATION <- study2_ca$Q60.1
study2_ca$INCOME <- study2_ca$Q59
study2_ca$LIBCON <- study2_ca$Q33
study2_ca$RISK <- abs(11-study2_ca$Q54)
study2_ca$INFORMED30 <- abs(6-study2_ca$Q124.1) #INFORMED ABOUT PROP 30
study2_ca$INFORMED34 <- abs(6-study2_ca$Q128) #INFORMED ABOUT PROP 34
study2_ca$IMPORT30 <- abs(6-study2_ca$Q123.1) #FEEL PROP 30 IS IMPORTANT
study2_ca$IMPORT34 <- abs(6-study2_ca$Q127) #FEEL PROP 34 IS IMPORTANT
study2_ca$BLACK <- as.numeric(study2_ca$Q37 == 2)
study2_ca$HISP <-  as.numeric(study2_ca$Q37 == 3)
study2_ca$WHITE <-  as.numeric(study2_ca$Q37 == 5)
########################
